package com.demo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicExChangeConfig {
    public final static String KEY1 = "topic.key.A";
    public final static String KEY2 = "topic.key.B";
    public final static String KEY3 = "topic.key.*";
    public final static String KEY4 = "topic.key.#";
    public final static String KEY5 = "topic.key.CC.DD";
    public final static String TOPIC_EXCHANGE_NAME = "topicExchange";

    @Bean
    public Queue queueA() {
        return new Queue("queueA");
    }

    @Bean
    public Queue queueB() {
        return new Queue("queueB");
    }

    @Bean
    public Queue queueC() {
        return new Queue("queueC");
    }

    @Bean
    TopicExchange getTopicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE_NAME);
    }

    @Bean
    Binding bindingA(){
        return BindingBuilder.bind(queueA()).to(getTopicExchange()).with(KEY1);
    }

    @Bean
    Binding bindingB(){
        return BindingBuilder.bind(queueB()).to(getTopicExchange()).with(KEY3);
    }
    @Bean
    Binding bindingC(){
        return BindingBuilder.bind(queueC()).to(getTopicExchange()).with(KEY4);
    }
}
